using System;
using Guestbook.business.service;
using Guestbook.business;

namespace Guestbook.domain
{
    public class Message : BusinessBase<Message, int>
    {
        #region - Fields & Propertes -

        private string _author;
        public string Author
        {
            get { return _author; }
            set { _author = value; }
        }

        private string _userEmail;
        public string UserEmail
        {
            get { return _userEmail; }
            set { _userEmail = value; }
        }

        private string _userWebsite;
        public string UserWebsite
        {
            get { return _userWebsite; }
            set { _userWebsite = value; }
        }

        private string _content;
        public string Content
        {
            get { return _content; }
            set { _content = value; }
        }

        private DateTime _dateCreation;
        public DateTime DateCreation
        {
            get { return _dateCreation; }
            set { _dateCreation = value; }
        }

        private bool _active;
        public bool Active
        {
            get { return _active; }
            set { _active = value; }
        }

        private int _parentId;
        public int ParentId
        {
            get { return _parentId; }
            set { _parentId = value; }
        }

        private int _number;
        public int Number
        {
            get { return _number; }
            set { _number = value; }
        }

        #endregion

        #region - Base overrides -

        ///// <summary>
        ///// Saves the object to the data store (inserts, updates or deletes).
        ///// </summary>
        ///// <returns></returns>
        //public override SaveAction Save()
        //{
        //  SaveAction action = base.Save();
        //  if (action == SaveAction.Insert || action == SaveAction.Update)
        //    _Content = null;

        //  return action;
        //}

        /// <summary>
        /// Validates the Post instance.
        /// </summary>
        protected override void ValidationRules()
        {
            //AddRule("Title", "Title must be set", String.IsNullOrEmpty(Title));
            //AddRule("Content", "Content must be set", String.IsNullOrEmpty(Content));
        }

        /// <summary>
        /// Returns a Post based on the specified id.
        /// </summary>
        protected override Message DataSelect(int id)
        {
            return GuestBookService.SelectMessagesById(id);
        }

        /// <summary>
        /// Updates the Post.
        /// </summary>
        protected override void DataUpdate()
        {
            GuestBookService.UpdateMessages(this);
        }

        /// <summary>
        /// Inserts a new post to the current BlogProvider.
        /// </summary>
        protected override void DataInsert()
        {
            GuestBookService.InsertMessage(this);
        }

        /// <summary>
        /// Deletes the Post from the current BlogProvider.
        /// </summary>
        protected override void DataDelete()
        {
            GuestBookService.DeleteMessagesById(this.Id);
        }

        /// <summary>
        /// Gets if the Post have been changed.
        /// </summary>
        public override bool IsChanged
        {
            get
            {
                if (base.IsChanged)
                    return true;

                return false;
            }
        }

        /// <summary>
        /// Marks the object as being an clean,
        /// which means not dirty.
        /// </summary>
        public override void MarkOld()
        {
            base.MarkOld();
        }

        /// <summary>
        /// Loads an instance of the object based on the Id.
        /// </summary>
        /// <param name="id">The unique identifier of the object</param>
        public new static Message Load(int id)
        {
            Message instance = new Message();
            instance = instance.DataSelect(id);
            instance.Id = id;
            if (instance != null)
            {
                instance.MarkOld();
                return instance;
            }
            return null;

        }

        #endregion

        // To String Stuffs
        public override string ToString()
        {
            return base.ToString();
        }
    }
}
